﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;


namespace Gp.Scripts.Core {
    public abstract class UnitGestureSequence : ModelAnimBase{
        public abstract IEnumerator PlayGestureSequence();

        /// <param name="isComplete">是否完整播放。如果是被终止，则为false</param>
        public virtual void OnKill(bool isComplete) { }

        /// <summary>
        /// 在animation中配置的动画事件回调。
        /// </summary>
        /// <param name="eventName">事件名</param>
        public virtual void OnAnimationEvent(string eventName) { }
    }


    /// <summary>
    /// Gesture 的事件版本。可以通过方法快速注册事件。
    /// </summary>
    public abstract class UnitEventGestureSequence : UnitGestureSequence {
        private Dictionary<string, Action> _eventDic;
        public override void OnAnimationEvent(string eventName) {
            if (_eventDic == null) return;
            if (_eventDic.TryGetValue(eventName, out var callBack)) {
                callBack();
            }
        }
        
        
        protected void EventListen(string eventName, Action onTrigger) {
            _eventDic ??= new Dictionary<string, Action>();
            _eventDic[eventName] = onTrigger;
        }


        protected void EventListen(UnitAnimEventType @event, Action onTrigger) {
            EventListen(@event.EventName(), onTrigger);
        }
    }
}